package com.hckjsec.common.utils.http;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

public class RequestUtil {

    public static String getReqInputStreamParam(HttpServletRequest req) throws Exception{
        ServletInputStream inputStream = req.getInputStream();
        return getInputStreamParam(inputStream);
    }


    public static String getInputStreamParam(InputStream inputStream) {
        StringBuffer result = new StringBuffer();
        try {
            BufferedReader br = new BufferedReader( new InputStreamReader( inputStream, "UTF-8" ) );
            String line = "";
            while ( ( line = br.readLine() ) != null )
            {
                result.append(line);
            }
        }catch (Exception e) {
            e.printStackTrace();
        }
        return result.toString();
    }
}
